//
//  ChoiceMercTypeAlertVM.swift
//  kxf
//
//  Created by Mac on 2024/3/10.
//

import Foundation
import UIKit

class ChoiceMercTypeAlertVM: UIView {
    
    var typeString = "mini"
    public var tapBlock:((String)->())?
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x:0, y: 0, width: SCREEN_WIDHT, height: SCREEN_HEIGHT))
        self.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.66)
        self.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(hiddenSelfAction))
        self.addGestureRecognizer(tap)
        
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(12)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(nothingToDo))
        vi.addGestureRecognizer(tap)
        
        return vi
    }()
    lazy var titleLabel : UILabel = {
        let lab = UILabel()
        lab.text = "修改商户类型"
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 18, weight: .medium)
        
        return lab
    }()
    lazy var miniLabel : UILabel = {
        let lab = UILabel()
        lab.text = "小微商户"
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 16, weight: .regular)
        lab.textAlignment = .center
        lab.layer.cornerRadius = kFitWidth(4)
        lab.clipsToBounds = true
        lab.layer.borderWidth = kFitWidth(1)
        lab.layer.borderColor = UIColor.THEME.cgColor
        lab.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(miniTapAction))
        lab.addGestureRecognizer(tap)
        
        return lab
    }()
    lazy var getiLabel : UILabel = {
        let lab = UILabel()
        lab.text = "个体户"
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 16, weight: .regular)
        lab.textAlignment = .center
        lab.layer.cornerRadius = kFitWidth(4)
        lab.clipsToBounds = true
        lab.layer.borderWidth = kFitWidth(1)
        lab.layer.borderColor = UIColor.white.cgColor
        lab.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(getiTapAction))
        lab.addGestureRecognizer(tap)
        
        return lab
    }()
    lazy var qiyeLabel : UILabel = {
        let lab = UILabel()
        lab.text = "企业用户"
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 16, weight: .regular)
        lab.textAlignment = .center
        lab.layer.cornerRadius = kFitWidth(4)
        lab.clipsToBounds = true
        lab.layer.borderWidth = kFitWidth(1)
        lab.layer.borderColor = UIColor.white.cgColor
        lab.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(qiyeTapAction))
        lab.addGestureRecognizer(tap)
        return lab
    }()
    lazy var confirmBtn : UIButton = {
        let btn = UIButton()
        btn.setTitle("确认修改", for: .normal)
        btn.setTitleColor(.white, for: .normal)
        btn.titleLabel?.font = .systemFont(ofSize: 14, weight: .regular)
        btn.layer.cornerRadius = kFitWidth(20)
        btn.clipsToBounds = true
        btn.backgroundColor = .THEME
        
        btn.addTarget(self, action: #selector(confirmBtnAction), for: .touchUpInside)
        
        return btn
    }()
}

extension ChoiceMercTypeAlertVM{
    @objc func miniTapAction() {
        if self.typeString == "mini"{
            return
        }
        self.typeString = "mini"
        setNormal()
        miniLabel.layer.borderColor = UIColor.THEME.cgColor
    }
    @objc func getiTapAction() {
        if self.typeString == "geti"{
            return
        }
        self.typeString = "geti"
        setNormal()
        getiLabel.layer.borderColor = UIColor.THEME.cgColor
    }
    @objc func qiyeTapAction() {
        if self.typeString == "qiye"{
            return
        }
        self.typeString = "qiye"
        setNormal()
        qiyeLabel.layer.borderColor = UIColor.THEME.cgColor
    }
    @objc func nothingToDo() {
        
    }
    @objc func hiddenSelfAction() {
        self.isHidden = true
    }
    @objc func confirmBtnAction() {
        if self.tapBlock != nil{
            self.tapBlock!(self.typeString)
        }
        self.isHidden = true
    }
    func setNormal() {
        miniLabel.layer.borderColor = UIColor.white.cgColor
        getiLabel.layer.borderColor = UIColor.white.cgColor
        qiyeLabel.layer.borderColor = UIColor.white.cgColor
    }
}
extension ChoiceMercTypeAlertVM{
    func initUI() {
        addSubview(whiteView)
        whiteView.addSubview(titleLabel)
        whiteView.addSubview(miniLabel)
        whiteView.addSubview(getiLabel)
        whiteView.addSubview(qiyeLabel)
        whiteView.addSubview(confirmBtn)
        
        setConstrait()
    }
    func setConstrait()  {
        whiteView.snp.makeConstraints { make in
            make.center.lessThanOrEqualToSuperview()
            make.width.equalTo(kFitWidth(280))
            make.height.equalTo(kFitWidth(271))
        }
        titleLabel.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(22))
        }
        miniLabel.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.width.equalTo(kFitWidth(107))
            make.height.equalTo(kFitWidth(35))
            make.top.equalTo(kFitWidth(61))
        }
        getiLabel.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.width.height.equalTo(miniLabel)
            make.top.equalTo(kFitWidth(102))
        }
        qiyeLabel.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.width.height.equalTo(miniLabel)
            make.top.equalTo(kFitWidth(143))
        }
        confirmBtn.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.width.equalTo(kFitWidth(114))
            make.height.equalTo(kFitWidth(40))
            make.bottom.equalTo(kFitWidth(-34))
        }
    }
}
